package com.example.my.agiftthat.MvpActivity;


import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.my.agiftthat.R;
import com.example.my.agiftthat.ui.classify.fragment.FragmentClassify;
import com.example.my.agiftthat.ui.home.fragment.FragmentHome;
import com.example.my.agiftthat.ui.list.FragmentList;
import com.example.my.agiftthat.ui.my.FragmentMy;
import com.example.my.agiftthat.ui.shop.FragmentShop;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {


    @Bind(R.id.linearLayout)
    LinearLayout linearLayout;
    @Bind(R.id.button_home)
    RadioButton buttonHome;
    @Bind(R.id.button_list)
    RadioButton buttonList;
    @Bind(R.id.button_shop)
    RadioButton buttonShop;
    @Bind(R.id.button_classify)
    RadioButton buttonClassify;
    @Bind(R.id.button_my)
    RadioButton buttonMy;
    @Bind(R.id.radioGroup)
    RadioGroup radioGroup;
    private FragmentManager manager;
    private FragmentTransaction transaction;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //解决radiogroup跟着输入法面板往上跑的问题
        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        //解决radiogroup跟着输入法面板往上跑的问题
        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        //动态设置底部导航栏图片的大小
        button();
//        //设置默认启动项
//        initManage();
//        transaction.add(R.id.linearLayout, new FragmentHome());
//        transaction.commit();
//        设置监听
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                initManage();
                switch (checkedId) {
                    case R.id.button_home:
                        transaction.replace(R.id.linearLayout, new FragmentHome());
                        break;
                    case R.id.button_list:
                        transaction.replace(R.id.linearLayout, new FragmentList());
                        break;
                    case R.id.button_shop:
                        transaction.replace(R.id.linearLayout, new FragmentShop());
                        break;
                    case R.id.button_classify:
                        transaction.replace(R.id.linearLayout, new FragmentClassify());
                        break;
                    case R.id.button_my:
                        transaction.replace(R.id.linearLayout, new FragmentMy());
                        break;

                }
                transaction.commit();
            }
        });

    }

    private void initManage() {
        manager = getSupportFragmentManager();
        transaction = manager.beginTransaction();
    }

    private void button() {
        //首页
        Drawable drawable1 = getResources().getDrawable(R.drawable.selector_home);
        drawable1.setBounds(0, 0, 60, 60);
        buttonHome.setCompoundDrawables(null, drawable1, null, null);
        //榜单
        Drawable drawable2 = getResources().getDrawable(R.drawable.selector_remen);
        drawable2.setBounds(0, 0, 60, 60);
        buttonList.setCompoundDrawables(null, drawable2, null, null);
        //商城
        Drawable drawable3 = getResources().getDrawable(R.drawable.selector_shop);
        drawable3.setBounds(0, 0, 60, 60);
        buttonShop.setCompoundDrawables(null, drawable3, null, null);
        //分类
        Drawable drawable4 = getResources().getDrawable(R.drawable.selector_fenlei);
        drawable4.setBounds(0, 0, 60, 60);
        buttonClassify.setCompoundDrawables(null, drawable4, null, null);
        //我的
        Drawable drawable5 = getResources().getDrawable(R.drawable.selector_wode);
        drawable5.setBounds(0, 0, 60, 60);
        buttonMy.setCompoundDrawables(null, drawable5, null, null);
    }
}
